package cn.iocoder.yudao.module.knowledge.service.elecsigninfo;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.knowledge.controller.admin.elecsigninfo.vo.*;
import cn.iocoder.yudao.module.knowledge.dal.dataobject.elecsigninfo.ElecSignInfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.knowledge.dal.mysql.elecsigninfo.ElecSignInfoMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.knowledge.enums.ErrorCodeConstants.*;

/**
 * 售电签约信息 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class ElecSignInfoServiceImpl implements ElecSignInfoService {

    @Resource
    private ElecSignInfoMapper elecSignInfoMapper;

    @Override
    public Long createElecSignInfo(ElecSignInfoSaveReqVO createReqVO) {
        // 插入
        ElecSignInfoDO elecSignInfo = BeanUtils.toBean(createReqVO, ElecSignInfoDO.class);
        elecSignInfoMapper.insert(elecSignInfo);

        // 返回
        return elecSignInfo.getId();
    }

    @Override
    public void updateElecSignInfo(ElecSignInfoSaveReqVO updateReqVO) {
        // 校验存在
        validateElecSignInfoExists(updateReqVO.getId());
        // 更新
        ElecSignInfoDO updateObj = BeanUtils.toBean(updateReqVO, ElecSignInfoDO.class);
        elecSignInfoMapper.updateById(updateObj);
    }

    @Override
    public void deleteElecSignInfo(Long id) {
        // 校验存在
        validateElecSignInfoExists(id);
        // 删除
        elecSignInfoMapper.deleteById(id);
    }

    @Override
        public void deleteElecSignInfoListByIds(List<Long> ids) {
        // 删除
        elecSignInfoMapper.deleteByIds(ids);
        }


    private void validateElecSignInfoExists(Long id) {
        if (elecSignInfoMapper.selectById(id) == null) {
            throw exception(ELEC_DATA_SIGN_INFO_NOT_EXISTS);
        }
    }

    @Override
    public ElecSignInfoDO getElecSignInfo(Long id) {
        return elecSignInfoMapper.selectById(id);
    }

    @Override
    public PageResult<ElecSignInfoDO> getElecSignInfoPage(ElecSignInfoPageReqVO pageReqVO) {
        return elecSignInfoMapper.selectPage(pageReqVO);
    }

}